package tech.yunjing.train.util;

import org.apache.commons.codec.binary.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by ZhangFan on 2017/6/8.
 * 工具类，md5加密使用
 */
public class PasswordUtil {
    /**
     * 加密方法
     *
     * @param md5 需要加密的字符串
     * @return String
     */
    public static String md5(String md5) {
        try {
            MessageDigest src = MessageDigest.getInstance("MD5");
            byte[] input = src.digest(md5.getBytes());
            String ret = Base64.encodeBase64String(input);
            return ret;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }
}
